<?php

namespace app\admin\model;
use think\Db;
use think\Model;

class CostConfig extends Model {

    public function __construct() {
        parent::__construct();
    }

    //费用配置列表
    public function getListInfo($page, $limit, $data) {
        $where = [];
        //省份ID
        if(isset($data['provinceId']) && $data['provinceId'] != ''){
            $where['province_id'] = $data['provinceId'];
        }
        //城市ID
        if(isset($data['cityId']) && $data['cityId'] != ''){
            $where['city_id'] = $data['cityId'];
        }
        $where['status'] = 1;
        //分页
        $start = ($page - 1) * $limit;
        $count = Db::name('price_rule')->where($where)->count();
        $list = Db::name('price_rule')->where($where)->limit($start, $limit)->order('id desc')->select();
        foreach ($list as $key=>$value){
            $list[$key]['admin_name'] = getAdminInfo($value['admin_id'],1);
            $list[$key]['add_time']   = date("Y-m-d H:i:s",$value['add_time']);
            //起步里程
            if(!empty($value['start_mileage'])){
                $list[$key]['start_mileage']    =  $value['start_mileage']/1000;
            }else{
                $list[$key]['start_mileage']    =  '-';
            }
            //起步时长
            if(!empty($value['start_time'])){
                $list[$key]['start_time']       =  $value['start_time']/60;
            }else{
                $list[$key]['start_time']       =  '-';
            }
            //起步价
            if(!empty($value['start_fee'])){
                $list[$key]['start_fee']        =  $value['start_fee']/100;
            }else{
                $list[$key]['start_fee']        =  '-';
            }
            //里程费
            if(!empty($value['mileage_fee'])){
                $list[$key]['mileage_fee']      =  $value['mileage_fee']/100;
            }else{
                $list[$key]['mileage_fee']      =  '-';
            }
            //时长费
            if(!empty($value['time_fee'])){
                $list[$key]['time_fee']         =  $value['time_fee']/100;
            }else{
                $list[$key]['time_fee']         =  '-';
            }
            //超时等待费
            if(!empty($value['over_wait_fee'])){
                $list[$key]['over_wait_fee']    =  $value['over_wait_fee']/100;
            }else{
                $list[$key]['over_wait_fee']    =  '-';
            }
        }
        return array(
            'code' => 0,
            'msg' => '',
            'count' => $count,
            'data' => $list
        );
    }
}
